#ifndef HRV_TIMECOMPUTE_H
#define HRV_TIMECOMPUTE_H
#include <QVector>
#include <QDebug>
#include <cmath>
#include <algorithm>
class HRV_TimeCompute
{
public:
    HRV_TimeCompute();
    // 时间域HRV计算
    struct TimeDomainHRV {
        double max;
        double min;
        double mean;
        double median;
        double SDNN;
        double SDANN;
        double NNx;
        double pNNx;
        double RMSSD;
        double SDNNi;
        double meanHR;
        double sdHR;
        double HRVTi;
        double TINN;
    };

    // 计算时间域HRV
    TimeDomainHRV timeDomainHRV(const QVector<double>& ibi, double win, double xx);

private:
    // 辅助函数
    double SDANN(const QVector<double>& ibi, double t);
    double SDNNi(const QVector<double>& ibi, double t);
    std::pair<double, double> pNNx(const QVector<double>& ibi, double x);
    double RMSSD(const QVector<double>& ibi);
    double hrvti(const QVector<double>& ibi, int nbin);
    double tinn(const QVector<double>& ibi, int nbin);
};

#endif // HRV_TIMECOMPUTE_H
